// pages/qiye_jieshao/qiye_jieshao.js
const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');
Page({
    data: {
        list: [],
        type: 1,
        navType: 0,
        isShow: true,
        year: '',
        month: '',
        loadingType: 0,
        contentText: {
            contentdown: "上拉显示更多",
            contentrefresh: "正在加载...",
            contentnomore: "没有更多数据了"
        },
        id: 0,
        allnumAdd: 0,
        allnumDec: 0
    },
    onLoad(options) {
        this.setData({
            type: options.type,
            navType: options.navType,
            id: options.id
        });
        const date = new Date();
        this.setData({
            year: date.getFullYear(),
            month: date.getMonth() + 1 > 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1)
        });
        this.sureload();
    },
    sureload() {
        if (this.data.type == 1) {
            wx.setNavigationBarTitle({
                title: '库存流水'
            });
            this.getinfo1();
        } else if (this.data.type == 2) {
            wx.setNavigationBarTitle({
                title: '补贴流水'
            });
            this.getinfo2();
        }
    },
    getinfo1() {
        const that = this;
        util.httpRrquest(app.data.apiurl + 'shop/getMyShopKucun', 'GET', { id: that.data.id,
                cateId: that.data.navType,
                year: that.data.year,
                month: that.data.month })
        .then(function (response) {
            var data = response.data.data;
            that.setData({
                list: data.child,
                allnumAdd: data.num1,
                allnumDec: data.num2
            });
        }, function (error) {
            console.log(error);
        });
    },
    getinfo2() {
        const that = this;
        util.httpRrquest(app.data.apiurl + 'shop/getMyShopButie', 'GET', { id: that.data.id,
                cateId: that.data.navType,
                year: that.data.year,
                month: that.data.month })
        .then(function (response) {
            var data = response.data.data;
            that.setData({
                list: data.child,
                allnumAdd: data.num1,
                allnumDec: data.num2
            });
        }, function (error) {
            console.log(error);
        });
        
    },
    bindDateChange: function(e) {
    var date = e.detail.value;
    var arr = date.split('-');
    this.setData({
      year: arr[0],
      month:arr[1]
    })

    this.sureload();
  }
});